package top.tenebrous.yzl.im.factory.channel;

import org.springframework.stereotype.Component;
import top.tenebrous.yzl.im.enums.ChannelType;
import top.tenebrous.yzl.im.handler.channel.Channel;
import top.tenebrous.yzl.im.message.Message;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yazhang6
 */
@Component
public class MessageChannelFactory<E extends Message> implements ChannelFactory<E> {

    private final Map<ChannelType, Channel<E>> CHANNEL_MAP = new ConcurrentHashMap<>();

    @Override
    public void register(ChannelType channelType, Channel<E> channel) {
        CHANNEL_MAP.put(channelType, channel);
    }

    @Override
    public Channel<E> getChannel(ChannelType channelType) {
        return CHANNEL_MAP.get(channelType);
    }

}
